(defun replace-quote()
  (interactive)
  (beginning-of-buffer)
  (move-end-of-line 1)
  (setq num (buffer-substring-no-properties 1 (point)))
  (beginning-of-buffer)
  (while (re-search-forward "," nil t)
    (replace-match "")
    )
  (beginning-of-buffer)
  (while (re-search-forward "\\([0-9]+/[0-9]+\\) \\([0-9]+/[0-9]+/[0-9]+\\) \\([S/MAU 0-9]+\\) \\(.*\\) \\([0-9]+/[0-9]+/[0-9]+\\) \\(Reconciled\\|Not Allocated\\|Correction\\) \\([A-Za-z]+\\) \\([0-9\\.]+\\) \\([0-9\\.]+ [C|D]\\)" nil t)
    (replace-match ",\\1,\\2,\\3,\\4,\\5,\\6,\\7,\\8,\\9,")
    )
  (beginning-of-buffer)
  (while (re-search-forward "\\([0-9]+/[0-9]+\\) \\([0-9]+/[0-9]+/[0-9]+\\) \\(.*\\) \\([0-9]+/[0-9]+/[0-9]+\\) \\(Reconciled\\|Not Allocated\\|Correction\\) \\([A-Za-z]+\\) \\([0-9\\.]+\\) \\([0-9\\.]+ [C|D]\\)" nil t)
    (replace-match ",\\1,\\2,,\\3,\\4,\\5,\\6,\\7,\\8,")
    )
  (beginning-of-buffer)
  (while (re-search-forward "^
" nil t)
    (replace-match "")
    )

  (beginning-of-buffer)
  (while (re-search-forward "^," nil t)
    (replace-match (format "%s," num))
    )

  (beginning-of-buffer)
  (kill-line)
  (kill-line)  
  )


(global-set-key [f3] 'replace-quote)

(defun abcdef()
  (interactive)
  (let ((i 0)
        (length-def (length abc))      
        )
    (while (< i length-def)
      (find-file (format "D:/workspace/account2/%s.txt" (pop def)))
      (replace-quote)
      (save-buffer)
      (kill-buffer (current-buffer))
      )
    )
  )

(setq abc '(11110 
11112
11113
11115
11120
11130
11140
11148
11150
11152
11153
11161
11162
11167
11169
11171
11185
11190
11230
11234
11236
11400
11406
11410
11740
11800
12210
12220
12310
12320
12410
12420
12432
12434
12510
12520
12610
12620
21120
21130
21150
21250
21252
21310
21330
21410
21420
21430
21450
21460
21480
21490
21491
21600
21650
21652
21660
21662
21850
21852
21910
21911
22540
23040
31100
37000
37050
37052
38000
39000
39999
40100
40110
41010
41020
41500
41700
41800
41802
41900
49000
50100
50101
50102
50104
51100
51500
51610
51620
51630
51640
51650
61050
61100
61110
61120
61150
61200
61202
61210
61220
61260
61300
61310
61312
61350
61400
61450
61550
61560
61650
61655
61660
61662
61750
61760
61768
61770
61772
61850
62100
62300
62400
62410
62420
62422
62430
62482
62483
62484
62485
62510
62511
62512
62513
62550
63110
63112
63114
63116
63122
63123
63132
63133
63134
63135
63136
63138
63139
63152
63153
63154
63155
63156
63157
63158
63159
63160
63172
63174
63176
63178
63182
63192
63193
63210
63220
63240
63243
63246
63247
63248
63249
63254
63255
63256
63257
63258
63259
63262
63264
63265
63274
63275
63276
63277
63278
63292
63293
63294
63295
63297
63298
63299
63300
64102
64105
64110
64115
64120
64125
65110
65120
65130
65131
65132
65135
65138
65140
65150
65152
65170
65190
66010
66012
66070
67010
67020
67030
67040
67050
67060
67070
67071
67072
67080
67090
67092
67094
67096
67510
67512
75220
81000
81500
82000
83000
83400
91000
92000))

\\([0-9]\\{5\\}\\) \\([0-9]+/[0-9]+\\) \\([0-9]+/[0-9]+/[0-9]+\\) \\(.*\\) \\([0-9]+/[0-9]+/[0-9]+\\) \\([A-Za-z]+\\) \\([A-Za-z]+\\) \\([0-9\\.]+\\) \\([0-9\\.]+ [C|D]\\)

;;=============================================================
;;=============================================================

(delete-region 1 2)

(defun foo()
  (interactive)
  (beginning-of-buffer)
  (while (re-search-forward "EduGate Gateway Pty Ltd
General Ledger \\[Detail\\]
1/01/14 To 31/03/14
9/04/14
[0-9]*:[0-9]*:[0-9]* PM
Page [0-9]*" nil t)
    (replace-match "")
    )
  )


(defun replace-quote()
  (interactive)
  (beginning-of-buffer)
  (while (re-search-forward "ID# Src Date Memo Debit Credit Job No. Net Activity Ending Balance
" nil t)
    (replace-match "")
    )
  )

;;  1-1100 to total
;;
;;
(defun split()
  (interactive)
  (beginning-of-buffer)
  (setq point-start 1)
  (while (re-search-forward "\\([0-9]*\\)-\\([0-9]+\\).*" nil t)
    (setq file-name (format "%s-%s" (match-string 1) (match-string 2)))
  
    (re-search-forward "Total" nil t)
;;    (replace-match "")
    
    (move-end-of-line 1)
    (setq point-end (point))
    (write-region point-start point-end (format "D:/workspace/account3/%s.txt" file-name))
    ;;(delete-region 1 point-end)
    (goto-char point-end)
    (forward-char)
    (setq point-start (point))
    )
  )

(setq abc '(1-1110.txt
1-1120.txt
1-1125.txt
1-1130.txt
1-1140.txt
1-1210.txt
1-1220.txt
1-1230.txt
1-1310.txt
1-1320.txt
1-1330.txt
1-1340.txt
1-1350.txt
1-2210.txt
1-2220.txt
1-2310.txt
1-2320.txt
1-2401.txt
1-2410.txt
1-2420.txt
1-2510.txt
1-2520.txt
1-2610.txt
1-2620.txt
2-1110.txt
2-1120.txt
2-1130.txt
2-1140.txt
2-1150.txt
2-1160.txt
2-1210.txt
2-1230.txt
2-1310.txt
2-1320.txt
2-1330.txt
2-1340.txt
2-1410.txt
2-1420.txt
2-1430.txt
2-1440.txt
2-1450.txt
2-1460.txt
2-1470.txt
2-1480.txt
2-1490.txt
2-1510.txt
2-1520.txt
2-1550.txt
2-1560.txt
2-2100.txt
2-2200.txt
3-1000.txt
3-2000.txt
3-8000.txt
3-9000.txt
3-9999.txt
4-1000.txt
4-2000.txt
4-3000.txt
6-0990.txt
6-1099.txt
6-1100.txt
6-1101.txt
6-1102.txt
6-1103.txt
6-1104.txt
6-1105.txt
6-1106.txt
6-1107.txt
6-1108.txt
6-1200.txt
6-1300.txt
6-1400.txt
6-1500.txt
6-1600.txt
6-1700.txt
6-1800.txt
6-1900.txt
6-2000.txt
6-2100.txt
6-2200.txt
6-2201.txt
6-2300.txt
6-2400.txt
6-2401.txt
6-2500.txt
6-2600.txt
6-2700.txt
6-2800.txt
6-2801.txt
6-2900.txt
6-2901.txt
6-3000.txt
6-3100.txt
6-3200.txt
6-3300.txt
6-4100.txt
6-4200.txt
6-4300.txt
6-4301.txt
6-4400.txt
6-4500.txt
6-4600.txt
6-4700.txt
6-4800.txt
6-4900.txt
6-5100.txt
6-5200.txt
6-5300.txt
6-5400.txt
6-5500.txt
6-6100.txt
6-6200.txt
6-6300.txt
6-6400.txt
6-7100.txt
6-7200.txt
6-7300.txt
8-1000.txt
8-2000.txt
9-1000.txt
9-2000.txt
9-3000.txt))





(defun test()
  ""
  (interactive)
  (split)
  (setq length-abc (length abc))
  (setq i 0)
  (while (< i length-abc)
    (find-file (format "D:/workspace/account3/%s" (nth i abc)))
    (csv-convert)
    (kill-buffer nil)
    (setq i (+ 1 i))
    )
  )

(defun test()
  ""
  (interactive)

  (setq length-abc (length abc))
  (setq i 0)
  (while (< i length-abc)
    (insert-file (format "D:/workspace/account3/%s" (nth i abc)))
    (setq i (+ 1 i))
    )
)



(defun csv-convert()
  ""
  (interactive)
  (beginning-of-buffer)
  (re-search-forward "\\([0-9]*\\)-\\([0-9]*\\).*" nil t)
  (setq file-name (format "%s-%s" (match-string 1) (match-string 2)))

  (beginning-of-buffer)
  (while (re-search-forward "^\\([0-9]*\\)-\\([0-9]*\\).*
" nil t)
    (replace-match "")
    )
  
  
  (beginning-of-buffer)
  (while (re-search-forward "\\$" nil t)
    (replace-match "")
    )

  (beginning-of-buffer)
  (while (re-search-forward "\\," nil t)
    (replace-match "")
    )

  (beginning-of-buffer)
  (while (re-search-forward "Beginning Balance:.*
" nil t)
    (replace-match "")
    )

  (beginning-of-buffer)
  (while (re-search-forward "\\([0-9A-Za-z]+\\) \\([A-Z]*\\) \\([0-9/]*\\) \\(.*\\) \\([0-9\.]*\\) \\([0-9\.]*\\)" nil t)
    (replace-match (format "%s,\\1,\\2,\\3,\\4,\\5,\\6" file-name))
    )

  (beginning-of-buffer)
  (while (re-search-forward "^
" nil t)
    (replace-match "")
    )

  (beginning-of-buffer)
  (while (re-search-forward "Total:.*" nil t)
    (replace-match "")
    )
  (save-buffer)
  )

(defun test()
  ""
  (interactive)
  (beginning-of-buffer)
  (while (re-search-forward "Total:.*" nil t)
    (replace-match "")
    )
  )

